import React, { useState, useEffect } from 'react';
import { connect } from 'dva';
import EditTemplate from '@/components/EditTemplate';
import CapitalSource from '@/pages/components/capitalSource';
const BuildEdit = ({ location, dispatch }: any) => {
  const [detail, setDetail] = useState(null);
  const { id, readOnly } = location.query;

  const updateUrl = '/api/examine/v1/person/update';
  const createUrl = '/api/examine/v1/person/create';
  const saveUrl = id ? updateUrl : createUrl;
  useEffect(() => {
    if (id) {
      dispatch({
        type: '$request/post',
        payload: {
          url: '/api/examine/v1/person/detail',
          data: {
            uuid: id,
            page: 0,
            size: 10,
          },
        },
      }).then(res => {
        console.log('储备项目申报详情：', res);
        setDetail(res);
      });
    }
  }, []);
  const filters = [
    {
      title: '基础信息',
      list: [
        {
          key: 'name',
          type: 'input',
          label: '姓名',
          placeholder: '请输入姓名',
          rules: [{ required: true }],
          span: 12,
        },
        {
          key: 'gender',
          type: 'radiogroup',
          label: '性别',
          span: 12,
          options: [
            {
              label: '男',
              value: 'MALE',
            },
            {
              label: '女',
              value: 'FEMALE',
            },
          ],
        },
        {
          key: 'idNo',
          type: 'input',
          label: '身份证号',
          placeholder: '请输入身份证号',
          span: 12,
        },
        {
          key: 'mobile',
          type: 'input',
          label: '手机号',
          placeholder: '请输入手机号',
          span: 12,
        },
        {
          key: 'title',
          type: 'input',
          label: '职称',
          placeholder: '请输入职称',
          span: 12,
        },
        {
          key: 'org',
          type: 'input',
          label: '工作单位',
          placeholder: '请输入工作单位',
          span: 12,
        },
        {
          key: 'domain',
          type: 'textarea',
          label: '擅长领域',
          placeholder: '请输入擅长领域',
          span: 24,
        },
      ],
    },
  ];

  return (
    <div>
      <EditTemplate
        filters={filters}
        initialValues={detail}
        updateUrl={saveUrl}
        readOnly={readOnly}
      />
    </div>
  );
};

export default connect((state: any) => state.auth)(BuildEdit);
